﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class NPS_app_MasterData_CPCategory : PageBase
{
    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (getMode == FormMode.Editor)
            {
                loadData();
                btnSave.Text = "Update";
                lblHeader.Text = "Master Data: Contact Person Category Edit";
            }
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        Entities.NPSCPCategory CPCategory = new Entities.NPSCPCategory()
        {
            sxTitle = setStringSecurity(txtTitle.Text),
            sxDetail = setStringSecurity(txtDetail.Text)
        };
        if (getMode == FormMode.Editor)
        {
            CPCategory.sxUpdater = ICPUser.ID;
            CPCategory.iID = getItemID;
            updateCPCategory(CPCategory);
        }
        else { saveCPCategory(CPCategory); }
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {

    }

    #endregion

    #region Audy's Custom Function
    protected void loadData()
    {
        //fetch data from DB
        Controller.NPSCPCategoryController ATController = new Controller.NPSCPCategoryController();
        Entities.NPSCPCategory CPCategory = ATController.getNPSCPCategory(getItemID);

        //set all data to forms
        txtTitle.Text = CPCategory.sxTitle;
        txtDetail.Text = CPCategory.sxDetail;
    }

    protected bool saveCPCategory(Entities.NPSCPCategory CPCategory)
    {
        Controller.NPSCPCategoryController CPController = new Controller.NPSCPCategoryController();
        if (CPController.InsertNPSCPCategoryData(CPCategory) == 0)
        { return false; }
        else { return true; }
    }

    protected void updateCPCategory(Entities.NPSCPCategory CPCategory)
    {
        Controller.NPSCPCategoryController CPController = new Controller.NPSCPCategoryController();
        CPController.UpdateNPSCPCategoryData(CPCategory);
    }
    #endregion
}
